package net.janeluo.rs.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import net.janeluo.rs.entity.RS_Orders;

import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.sql.Criteria;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.service.Service;

/**
 * 我的订单业务类
 * 
 * @author DLK)JaneLuo
 * @version 1.0.0
 */
@IocBean(fields = { "dao" })
public class MyOrderService extends Service {
    private static final Log log = Logs.getLog(MyOrderService.class);

    public MyOrderService() {
        super();
    }

    public MyOrderService(Dao dao) {
        super(dao);
    }
    
    /**
     * 我的订单查询
     * 
     * @return
     */
    public List<RS_Orders> myOrderList(String userid, String type){
        log.debug("============= 我的订单查询处理开始 =============");
        
        // 我的订单列表
        Criteria cri = Cnd.cri();
        cri.where().andEquals("userid", userid);
        if ("1".equals(type)) {
            SimpleDateFormat sd = new SimpleDateFormat("yyyy/MM");
            cri.where().andLike("orderTime", sd.format(new Date()));
        } else {
            SimpleDateFormat sd = new SimpleDateFormat("yyyy/MM");
            cri.where().and("orderTime", " < ", sd.format(new Date()) + "/01 00:00");
        }
        List<RS_Orders> list = dao().fetchLinks(dao().query(RS_Orders.class, cri), "menu");
        
        log.debug("============= 我的订单查询处理结束 =============");
        return list;
    }
}
